//
// Created by DengLibin on 2019/1/9 0009.
//

#include <iostream>
#include <vector>
using namespace std;


int max_52(int x, int y){
    return (x > y ? x : y);
}
int min_52(int x, int y){
    return (x < y ? x : y);
}
/**
 * 盛水最多的容器 双指针法
 * @return
 */
int maxArea(vector<int>& height) {
    int maxArea = 0;
    int leftIndex = 0;
    int rightIndex = height.size() -1;
    while(leftIndex < rightIndex){
         maxArea = max_52(maxArea, (rightIndex - leftIndex) * min_52(height[leftIndex],height[rightIndex]));
        if(height[leftIndex] < height[rightIndex]){
            leftIndex ++;
        }else{
            rightIndex --;
        }
    }
    return maxArea;

}

int main52(){
    vector<int> v;
    v.push_back(1);
    v.push_back(8);
    v.push_back(6);
    v.push_back(2);
    v.push_back(5);
    v.push_back(4);
    v.push_back(8);
    v.push_back(3);
    v.push_back(7);
    cout << maxArea(v);
    return 0;
}